package optimizers.tools;


import java.io.FileInputStream;
import java.io.ObjectInputStream;

import optimizers.commons.GAConstants;
import optimizers.commons.GAIndiv;

public class GenomeReader {
	
	public static double[] getGenome(int index){
		int nbOfSequences = GAConstants.noOfSimpleSeq+2;
		double[] ret = new double[nbOfSequences*nbOfSequences*(nbOfSequences+1)+nbOfSequences*(nbOfSequences+1)+nbOfSequences+1];
		
		FileInputStream saveFile;
		GAIndiv[] curGen = new GAIndiv[GAConstants.populationSize];
		try {
			saveFile = new FileInputStream("initGeneration.dat");
			ObjectInputStream restore = new ObjectInputStream(saveFile);
			curGen = (GAIndiv[]) restore.readObject();
			restore.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		curGen[index] = curGen[index].addTwoSimpleSequences(); // format utilisable
		
		int where=0;
		// templates
		for(int i=0;i<nbOfSequences+1;i++){
			for(int j=0; j<nbOfSequences;j++){
				for(int k=0; k<nbOfSequences;k++){
					ret[where] = curGen[index].oligoModel.template[i][j][k];
					where++;
				}
			}
		}
		//sequences concentration
		for(int i=0;i<nbOfSequences+1;i++){
			for(int j=0; j<nbOfSequences;j++){
					ret[where] = curGen[index].oligoModel.seqConcentration[i][j];
					where++;
			}
		}
		//seqK
		for(int i=0;i<nbOfSequences;i++){
			ret[where] = curGen[index].oligoModel.seqK[0][i];
			where++;
		}
		//exo
		ret[where] = curGen[index].oligoModel.exo;
		return ret;
	}

	
	public static void main(String[] args) {
		GenomeReader genomeReader = new GenomeReader(); // remarque: getGenome pourrait etre static
		//System.out.println( GenomeReader.getGenome(0) );		
		
		double [] genome = GenomeReader.getGenome(0);
		
		for ( int i = 0 ; i < genome.length ; i++ )
			System.out.print(genome[i] + ", ");
		System.out.println("\ngenome length : " + genome.length );
		
	}	

}
